package task;

/**
 * 带返回结果的任务
 * @author wxhntmy
 */
public class ReturnResultTask implements Runnable {

    /**
     * 任务名称
     */
    private String name;

    /**
     * 构造函数
     * @param name 任务名称
     */
    public ReturnResultTask(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(this.toString() + " is running!");
        try {
            //让任务执行慢点
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.toString() + " is end!");
    }

    /**
     * 获取任务名称
     * @return 任务名称
     */
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "MyTask [ name = " + name + " ]";
    }
}
